package com.sf.admin.moniter;

import com.sf.admin.model.vo.ServerInfo;
import com.sf.admin.service.DbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;

@Service
public class MonitorService {

	@Autowired
	private DbService dbService;

	public ServerInfo getServerInfo() {
		ServerInfo sInfo = null;
		// 获取服务器环境
		Properties props = System.getProperties();
		String env = props.getProperty("java.version");// 服务器运行环境
		env = "java:"+env;
		String osName = props.getProperty("os.name");// 操作系统名称
		try {
			InetAddress address = InetAddress.getLocalHost();
			String hostName = address.getHostName();// 获取主机名称
			String hostIp = address.getHostAddress();// 获取主机ip
			// 获取数据库版本
			String dbVersion = dbService.getDbVersion();
			sInfo = new ServerInfo(env, osName, hostName, hostIp, "mysql", dbVersion);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return sInfo;
	}


}
